package com.tide.crm.dao;

import java.util.List;
import java.util.Map;

import com.tide.crm.model.ConvergeRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


@Mapper
public interface ConvergeRoleDao {

    @Select("select * from converge_role t where t.id = #{id}")
    public ConvergeRole getById(Long id);

    @Delete("delete from converge_role where id = #{id}")
    public int delete(Long id);

    public int update(ConvergeRole convergeRole);
    
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into converge_role(id, create_date, modify_date, role_name, role_code) values(#{id}, now(), now(), #{roleName}, #{roleCode})")
    public int save(ConvergeRole convergeRole);
    
    public int count(@Param("params") Map<String, Object> params);

    public List<ConvergeRole> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);
    
    
    @Select("select * from converge_role t where t.role_name = #{name}")
    public ConvergeRole getRole(String name);
    
    @Delete("delete from sys_role_permission where roleId = #{roleId}")
	int deleteRolePermission(Long roleId);
    
    
    int saveRolePermission(@Param("roleId") Long roleId, @Param("permissionIds") List<Long> permissionIds);
}
